package com.imay.live.adapter;


import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.live.R;
import com.imay.live.helper.LevelHelper;
import com.imay.live.logic.NoticeListLogic;
import com.imay.live.model.NoticeModel;
import com.imay.live.utils.GlideUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by  nick on 2017/4/5 0005.
 * 通知列表
 */

public class NoticeListAdapter extends  BaseQuickAdapter<NoticeModel, BaseViewHolder> {

    public NoticeListAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, NoticeModel item) {
        ImageView iv_notice_right = helper.getView(R.id.iv_notice_right);
        ImageView iv_notice_head_img = helper.getView(R.id.iv_notice_head_img);
        RecyclerView rcv_notice_feed = helper.getView(R.id.rcv_notice_feed);


        helper.setText(R.id.tv_notice_content, NoticeListLogic.getTextMine(mContext,item));
        ((TextView)helper.getView(R.id.tv_notice_content)).setMovementMethod(LinkMovementMethod.getInstance());//设置点击监听
        if (item.getUsers()!=null&&!item.getUsers().isEmpty()){
            GlideUtil.loadCircleImage(iv_notice_head_img,item.getUsers().get(0).getImgHead(),R.mipmap.pnl_00_head108);
            helper.setImageResource(R.id.iv_vip, LevelHelper.getVIPIcon(item.getUsers().get(0).getVip()));
        }
        iv_notice_right.setVisibility(View.GONE);
        rcv_notice_feed.setVisibility(View.GONE);
        if (item.getFeeds()!=null){
            if (item.getFeeds().size()==1){
                iv_notice_right.setVisibility(View.VISIBLE);
                GlideUtil.loadImage(iv_notice_right,item.getFeeds().get(0).getUrl(),R.mipmap.placeholder);
            } else{
                rcv_notice_feed.setVisibility(View.VISIBLE);
                rcv_notice_feed.setLayoutManager(new GridLayoutManager(mContext,5));
                if (item.getFeeds().size()>10){
                    List<NoticeModel.NoticeFeedModel> newList = new ArrayList<>(10);
                    for (int i = 0; i <10 ; i++) {
                        newList.add(item.getFeeds().get(i));
                    }
                    rcv_notice_feed.setAdapter(new NoticeListFeedsAdapter(newList));
                }else{
                    rcv_notice_feed.setAdapter(new NoticeListFeedsAdapter(item.getFeeds()));
                }

            }
        }
        helper.setVisible(R.id.cb_notice_follow,false);
        if (!item.isMerge()&&item.getEventType()==1){
            if (!item.getUsers().get(0).isMyFollow()){
                helper.setChecked(R.id.cb_notice_follow,false);
                helper.setVisible(R.id.cb_notice_follow,true);
            }

        }

        helper.addOnClickListener(R.id.iv_notice_head_img);
        helper.addOnClickListener(R.id.iv_notice_right);
        helper.addOnClickListener(R.id.cb_notice_follow);

    }







}
